<template>
  <el-dialog :title="title" :visible.sync="open" width="90%" append-to-body :close-on-click-modal="false" v-dialogDrag>
    <div style="margin-left: 10px;">
      <div style=" display: flex;align-items: center;margin-bottom: 10px;margin-top: 10px;">
      </div>

      <el-form :model="queryParams" ref="queryForm" :inline="true" size="small" v-show="showSearch" label-width="98px">
        <el-form-item label="发货编号" prop="nos">
          <el-input v-model="queryParams.nos" placeholder="请输入发货编号" style="width: 220px;" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="通知单编号" prop="tongzhiNo">
          <el-input v-model="queryParams.tongzhiNo" placeholder="请输入通知单编号" style="width: 220px;" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="联系人" prop="linkman">
          <el-input v-model="queryParams.linkman" placeholder="请输入联系人" style="width: 220px;" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="联系电话" prop="linktel">
          <el-input v-model="queryParams.linktel" placeholder="请输入联系电话" style="width: 220px;" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="客户名称" prop="kehuName">
          <el-input v-model="queryParams.kehuName" placeholder="请输入客户名称" style="width: 220px;" clearable
            @keyup.enter.native="handleQuery" />
        </el-form-item>

        <el-form-item style="margin-left: 20px;">
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>

      </el-form>

      <el-form ref="form" :rules="rules" label-width="120px">
        <el-table :data="columns" ref="dragTable" row-key="id" v-loading="loading" @sort-change="handleSortChange">
          <el-table-column sortable label="发货编码" align="center" prop="nos" show-overflow-tooltip />
          <el-table-column sortable label="通知单编号" align="center" prop="tongzhiNo" show-overflow-tooltip />
          <el-table-column sortable label="发货日期" align="center" prop="fahuoDate" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.fahuoDate, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column sortable label="交货日期" align="center" prop="jiaohuoDate" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.jiaohuoDate, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column sortable label="联系人" align="center" prop="linkman" />
          <el-table-column sortable label="联系电话" align="center" prop="linktel" show-overflow-tooltip />
          <el-table-column sortable label="发货状态" align="center" prop="status">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.yifahuo_status" :value="scope.row.status" />
            </template>
          </el-table-column>
          <el-table-column sortable label="客户名称" align="center" prop="kehuName" show-overflow-tooltip />
          <el-table-column sortable label="到货日期" align="center" prop="daohuoDate" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.daohuoDate, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="到货回执" align="center" prop="daohuoFile" />
          <el-table-column label="备注" align="center" prop="remark" />
          <el-table-column align="center" class-name="small-padding fixed-width" label="操作" width="140">
            <template slot-scope="scope">
              <el-button size="mini" type="text" icon="el-icon-edit" @click="xiangqing(scope.row)">发货单详情</el-button>
              <el-button size="mini" type="text" icon="el-icon-edit" v-if="scope.row.status==3 || scope.row.status==0 "
                @click="modify(scope.row)">修改发货单</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-form>
      <yiFahuo-list ref="fahuomingxiList" @ok="getList"></yiFahuo-list>
      <lvFahuoBohui-form ref="modifyfahuomingxi" @ok="getList"></lvFahuoBohui-form>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import {
    getAction,
    addAction,
    getById
  } from '@/api/manage'
  import YiFahuoList from '@/views/develop/lvYifahuomingxi/YiFahuoList'
  import LvFahuoBohuiForm from '@/views/develop/lvYifahuomingxi/module/LvFahuoBohuiForm'
  export default {
    dicts: ['yifahuo_status'],
    name: "FahuodanList",
    components: {
      YiFahuoList,
      LvFahuoBohuiForm,
    },
    data() {
      return {
        title: "发货单",
        open: false,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        rows: [],
        rules: {},
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 销售信息管理表格数据
        dataList: [],
        columns: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 20000,
          nos: null,
          name: null,
          fahuoDate: null,
          jiaohuoDate: null,
          linkman: null,
          linktel: null,
          address: null,
          status: null,
          jingli: null,
          kehuId: null,
          kehuName: null,
          taxNo: null,
          taxCode: null,
          taxDate: null,
          taxMoney: null,
          taxShengyu: null,
          taxAllmoeny: null,
          allMoney: null,
          shengyu: null,
          yihui: null,
          daohuoDate: null,
          daohuoFile: null,
          tongzhiId: null,
          tongzhiNo: null,
          params: {},
        },
        url: {
          list: '/lvYifahuo/lvYifahuo/list',
        },
        tableMaxHeight: window.innerHeight - 320,
      };
    },
    created() {
      // this.intDictsForPrj();
      window.addEventListener('resize', this.getTableHeight);
    },
    destroyed() {
      window.removeEventListener('resize', this.getTableHeight);
    },
    methods: {
      modify(row) {
        this.$refs.modifyfahuomingxi.showModifyMingxi(row);
      },
      xiangqing(row) {
        this.$refs.fahuomingxiList.showMingxi(row);
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      getTableHeight() {
        this.tableHeight = window.innerHeight - 320
      },
      showFahuodanList(row) {
        this.queryParams.tongzhiId = row.id;
        this.open = true;
        this.getList();
      },
      /** 查询销售信息管理列表 */
      getList() {
        this.loading = true;
        getAction(this.url.list, this.queryParams).then(response => {
          this.columns = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 排序触发事件 */
      handleSortChange(column, prop, order) {
      this.queryParams.orderByColumn = column.prop;
      this.queryParams.isAsc = column.order;
      this.handleQuery();
    },
      /** 重置按钮操作 */
      resetQuery() {
        this.queryParams.params = {}
        this.resetForm("queryForm");
        this.handleQuery();
      },
    }
  };
</script>
